package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.web.ProxyService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 代理统计
 * @作者 田应平
 * @版本 v1.0
 * @创建时间 2023-07-18 15:23
 * @QQ号码 444141300
 * @Email service@dwlai.com
 * @官网 http://www.fwtai.com
*/
@RestController
@RequestMapping("/proxy")
public class ProxyController{

  private final ProxyService proxyService;

  public ProxyController(final ProxyService proxyService){
    this.proxyService = proxyService;
  }

  //获取代理统计数据
  @PreAuthorize("hasAuthority('proxy_btn_getProxyTree')")
  @GetMapping("/getProxyTree")
  public void getProxyTree(final Long kid,final Integer grade,final HttpServletResponse response){
    ToolClient.responseJson(proxyService.getProxyTree(kid == null ? 0 : kid,grade).replaceAll("\"false\"","false").replaceAll("\"true\"","true"),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('proxy_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(proxyService.listData(new PageFormData(request)),response);
  }

  /**查看订单*/
  @PreAuthorize("hasAuthority('proxy_row_view')")
  @GetMapping("/getViewOrder")
  public void getViewOrder(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(proxyService.getViewOrder(new PageFormData(request)),response);
  }

  /**查看订单详情*/
  @PreAuthorize("hasAuthority('proxy_order_row_queryById')")
  @GetMapping("/getViewOrderInfo")
  public void getViewOrderInfo(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(proxyService.getViewOrderInfo(id),response);
  }

  /**修改密码重置密码*/
  @PreAuthorize("hasAuthority('proxy_row_edit')")
  @PostMapping("/editUser")
  public void editUser(final Long userId,final String user_password,final String verify_password,final HttpServletResponse response){
    ToolClient.responseJson(proxyService.editUser(userId,user_password,verify_password),response);
  }
}